/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.publish.service;

import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.service.CrudService;
import com.thinkgem.jeesite.modules.equipment.entity.EleEquipment;
import com.thinkgem.jeesite.modules.publish.dao.EleSourceGroupPublishDao;
import com.thinkgem.jeesite.modules.publish.entity.EleSourceGroupPublish;
import com.thinkgem.jeesite.modules.sys.entity.User;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 资源发布包Service
 * @author unnamed
 * @version 2017-06-04
 */
@Service
@Transactional(readOnly = true)
public class EleSourceGroupPublishService extends CrudService<EleSourceGroupPublishDao, EleSourceGroupPublish> {

	public EleSourceGroupPublish get(String id) {
		return super.get(id);
	}
	
	public List<EleSourceGroupPublish> findList(EleSourceGroupPublish eleSourceGroupPublish) {
		return super.findList(eleSourceGroupPublish);
	}
	public List<EleSourceGroupPublish> findListByEquipmentId(String equipmentId,String status) {
		return dao.findListByEquipmentId(equipmentId, status);
	}
	public List<EleSourceGroupPublish> findListByEquipments(List<EleEquipment> list,String status) {
		return dao.findListByEquipments(list, status);
	}
	public Page<EleSourceGroupPublish> findPage(Page<EleSourceGroupPublish> page, EleSourceGroupPublish eleSourceGroupPublish) {
		return super.findPage(page, eleSourceGroupPublish);
	}
	public Page<EleSourceGroupPublish> findPageForCheck(Page<EleSourceGroupPublish> page, List<User> users,String status) {
		page.setList(dao.findEleEleSourceGroupForCheck(users, status));
		return page;
	}
	@Transactional(readOnly = false)
	public void updatePublishStatus(String publishId,String status) {
		dao.updatePublishStatus(publishId, status);
	}
	@Transactional(readOnly = false)
	public void save(EleSourceGroupPublish eleSourceGroupPublish) {
		super.save(eleSourceGroupPublish);
	}
	
	@Transactional(readOnly = false)
	public void delete(EleSourceGroupPublish eleSourceGroupPublish) {
		super.delete(eleSourceGroupPublish);
	}

	@Transactional(readOnly = false)
	public void batchInsertSource(List<EleSourceGroupPublish> publishList){
		for(EleSourceGroupPublish entity : publishList){
			if(entity.getIsNewRecord()){
				entity.preInsert();
			}
		}
		 Map<String,List<EleSourceGroupPublish>> params = new HashMap<String,List<EleSourceGroupPublish>>();
	        params.put("list", publishList);
		dao.batchInsertSource(params);
	}

	@Transactional(readOnly = false)
	public int dealApplyGroupStatus(String groups,String status){
		return dao.dealApplyGroupStatus(groups, status);
	}
	@Transactional(readOnly = false)
	public int dealApprovalGroupStatus(String groups,String status){
		return dao.dealApprovalGroupStatus(groups, status);
	}
	@Transactional(readOnly = false)
	public int bathcUpdateGroupStatus(String groups,String status,String checker){
		return dao.batchUpdateGroupStatus(groups, status,checker);
	}
}